fix: forward style prop to Modal inner container View#56181
Conversation
Modal accepts `style` via ViewProps but silently discards it.
The inner container View only applies `styles.container` and
`containerStyles` (which handles `backdropColor`/`transparent`),
ignoring any style prop passed by the consumer.
This means `<Modal style={{ padding: 20 }}>` has no effect even
though the types allow it.
Forward `this.props.style` as the last element in the style array
so consumer styles are applied and can override defaults.
|
Hi @AnuMessi10! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
@AnuMessi10 would it be able to achieve something similar by wrapping Modal under View and set style on the view? Since this.props.style is appended last, it can silently override backdropColor and transparent={true}. Someone passing style={{ backgroundColor: 'blue' }} would unintentionally break their transparent modal. |
…prop
Reorder the style array so explicit Modal API props (transparent,
backdropColor) always win over the generic style prop. Move the
default backgroundColor into styles.container so user styles can
override the default but not the explicit props.
Precedence: styles.container (default white) → this.props.style → containerStyles
- <Modal style={{ backgroundColor: 'red' }}> → red (user overrides default)
- <Modal transparent> → transparent (explicit prop wins over style)
- <Modal transparent style={{ backgroundColor: 'red' }}> → transparent wins
- <Modal backdropColor="blue" style={{ backgroundColor: 'red' }}> → blue wins
- <Modal style={{ padding: 20 }}> → works, no conflicts
|
@zeyap Good catch — thanks for the feedback! On wrapping Modal in a View: That won't work because Modal renders its children in a separate native overlay/window, not within the normal view hierarchy. A parent On the override concern: You're right — the initial implementation had The new precedence chain is: Key changes:
This means:
|
|
Warning JavaScript API change detected This PR commits an update to
This change was flagged as: |
|
The The only new behavior is that |
|
@zeyap has imported this pull request. If you are a Meta employee, you can view this in D101170804. |
|
This pull request was successfully merged by @AnuMessi10 in f8fa76f When will my fix make it into a release? | How to file a pick request? |
Summary:
Modalaccepts astyleprop viaViewProps(sinceModalPropsspreads...ViewProps) but silently discards it. The inner container<View>only appliesstyles.containerandcontainerStyles(which handlesbackdropColor/transparent), so any style passed by the consumer has no effect.For example,
<Modal style={{ padding: 20 }}>compiles without errors but the padding is never applied.This PR forwards
this.props.styleto the inner container View with a carefully designed precedence chain:containerStylesnow only setsbackgroundColorwhentransparentorbackdropColorare explicitly passed, ensuring these Modal-specific API props always take precedence over the genericstyleprop while still allowing consumers to customize other style properties.Precedence examples:
<Modal style={{ backgroundColor: 'red' }}><Modal transparent><Modal transparent style={{ backgroundColor: 'red' }}><Modal backdropColor="blue" style={{ backgroundColor: 'red' }}><Modal style={{ padding: 20 }}>Changelog:
[GENERAL] [FIXED] - Forward
styleprop to Modal's inner container View with correct precedence so consumer styles are applied without overridingtransparentorbackdropColorTest Plan:
Render a Modal with a custom style prop:
Before fix:
paddingandbackgroundColorare silently ignoredAfter fix: The modal container has 40px padding and a red background
Also verified that:
transparent={true}always produces a transparent background, even ifstyle={{ backgroundColor }}is setbackdropColoralways takes precedence overstyle.backgroundColorstyleprop) is unchanged — white background